extends Panel

# 偏移量
var offset = Vector2(20, 20) 

func _process(delta):
	var mouse_pos = get_global_mouse_position()
	var screen_size = get_viewport_rect().size
	var my_size = size
	var target_pos = mouse_pos + offset
	#检查右边界，如果超出就翻转
	if target_pos.x + my_size.x > screen_size.x:
		target_pos.x = mouse_pos.x - my_size.x - offset.x
	#检查下边界
	if target_pos.y + my_size.y > screen_size.y:
		target_pos.y = mouse_pos.y - my_size.y - offset.y
	
	global_position = target_pos

func limit_position_on_screen():
	# 获取当前视口（屏幕）的大小
	var screen_size = get_viewport_rect().size
	
	# 计算面板右下角的坐标限制
	var max_x = screen_size.x - size.x
	var max_y = screen_size.y - size.y
	
	global_position.x = clamp(global_position.x, 0, max_x)
	global_position.y = clamp(global_position.y, 0, max_y)
